package com.chensf.studydemo.common

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.chensf.studydemo.R
import kotlinx.android.synthetic.main.fragment_bubble_layout_test.*

class BubbleLayoutDemo :Fragment(){
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return layoutInflater.inflate(R.layout.fragment_bubble_layout_test, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        imageClip.setOnClickListener {
            val foo = formatNumberWithMarkSplit(123456,",",3)
            Log.e("foo", "foo: $foo")
        }
    }


    private fun formatNumberWithMarkSplit(
        number: Long,
        splitChar: String,
        splitLength: Int
    ): String {
        val tempSplitStr = StringBuilder()
        val numberStr = number.toString() + ""
        var count = 1
        for (index in numberStr.length-1 downTo 0) {
            val ch = numberStr[index]
            tempSplitStr.append(ch)
            if (count % splitLength == 0 && count != numberStr.length) {
                tempSplitStr.append(splitChar)
            }
            count++
        }
        return tempSplitStr.toString().reversed()
    }
}